﻿$(function () {
    var url = new Url();
    var $Id = url.GetQueryString("orderId");
    $.getJSON(//绑定订单
            "../Handler/FinancialOrder.ashx",
            { Id: $Id, type: 4, _: Math.random() },
            function (result) {
                if (result.Status) {

                    if (result.Data.Order.ContractStartDate == "") {
                        $(".startDate").css('display', 'none');
                    }
                    if (result.Data.Order.ContractEndDate == "") {
                        $(".endDate").css('display', 'none');
                    }

                    $("#orderData div[data-name]").each(function (index, item) {
                        $(this).text(result.Data.Order[$(this).attr("data-name")]);
                    });
                    $(".IsSameBank").text((result.Data.Order.IsSameBank ? "是" : "否"));
                    if (!result.Data.Order.IsSameBank) {
                        $("div.transferBank").css("display", "block");
                    }
                    $(".divEndDateTitle").html(GetEndDateName(result.Data.Order.PTypeId));

                    $("div[data-plan='IsFortunePlan']").text((result.Data.Order.IsFortunePlan ? "是" : "否"));

                    $("div[data-plan='IsFuinn']").text((result.Data.Order.IsFuinn ? "是" : "否"));

                    if (result.Data.Order.IsFuinn) {
                        $(".divCMName").show();
                    }
                    if (result.Data.Order.JumpProfitIncome) {
                        $(".JumpProfitIncome").show();
                        $(".JumpProfit").show(); 
                        GetOrdersList($Id);
                        GetProfit($Id);
                    }
                    if (result.Data.Order.VerifyStatus == 3) {
                        $("#backTitle").css("display", "inline");
                        $("#backReason").text(result.Data.Order.VerifyMemo);
                    }
                    if (result.Data.User) {
                        $("#userData div[data-name]").each(function (index, item) {
                            $(this).text(result.Data.User[$(this).attr("data-name")]);
                        });
                    }
                }
                else {
                    alert(result.Message);
                }
            }
        );
    //返回
    $(".btnReturn").bind('click', function () {
        history.go(-1);
        return false;
    });
    //获取文件列表
    $(".fileList").click(function () {
        $.getJSON("../Handler/FileHandler.ashx", { OrderId: $Id, type: 2, _: Math.random() }, function (result) {
            if (result.length > 0) {
                $(".contract_list").empty();
                $.each(result, function (index, item) {
                    $("#fileTemplate").tmpl(item).appendTo($(".contract_list"));
                });
                $(".preview").css("cursor", "pointer").click(function () {
                    $("#imgView").attr("src", $(this).attr("link"));
                });
            }
            else {
                $(".contract_list").text("暂无相关文件！");
            }
        });
    });

})
var isMax = false;
var i = 500;
window.onmousewheel = function (e) {
    e = e || window.event;
    var scrollValue = 0;
    if (e.wheelDelta) {//IE/Opera/Chrome 
        scrollValue = e.wheelDelta;
    } else if (e.detail) {//Firefox 
        scrollValue = e.detail;
    }
    $("#imgView").width(i);
    $("#myModal").scrollLeft(i);
    if (scrollValue > 0) {
        i = i + 20;
        if (i > 1500) {
            i = 1500;
        }
    }
    else {
        i = i - 20;
        if (i < 500) {
            i = 500;
            $(".modal-content").width(200);
        }
    }
}

//结束日期标题
function GetEndDateName($Id) {
    var product = new Product();
    var entity = product.GetInfoById($Id);
    if (entity != null) {
        if (entity.FinancialMode == 1) {
            return "封闭结束日期：";
        }
        else {
            return "合同结束日期：";
        }
    }
    else {
        return "合同结束日期：";
    }
}
//关联订单
function GetOrdersList($Id) {
    var strhtml = "";
    $.ajax({
        url: "../Handler/FinancialOrder.ashx",
        type: "post",
        data: { "type": 34, "OrderId": $Id },
        dataType: 'json',
        async: false,
        cache: false,
        success: function (result) {
            if (result.Status) {
                $(result.Data).each(function (index, item) {
                    strhtml += "<a href='" + window.location.pathname + "?orderId=" + item.OrderId + "&css=1020" + "'>" + item.OrderId + "</a>,";
                });
                strhtml= strhtml.substring(0, strhtml.length - 1);
            }
            else {
            }
        }
    });
    $("#RelatedOrderList").html(strhtml);
}
function GetProfit($Id) {
    $.ajax({
        url: "../Handler/FinancialOrder.ashx",
        type: "post",
        data: { "type": 38, "OrderId": $Id },
        dataType: 'json',
        async: false,
        cache: false,
        success: function (result) {
            if (result.Status) {
                $("#JumpProfit").text(result.Data.Profit);
                $("#SumJumpProfit").text(result.Data.SumProfit);
                $("#BackAcountname").text(result.Data.BackAcountname);
                $("#BackAccountNum").text(result.Data.BackAccountNum);
                $("#BackBankName").text(result.Data.BackBankName);
            }
            else {
            }
        }
    });
}
//关联订单共可享受收益
function GetEndDateName($Id) {
    var product = new Product();
    var entity = product.GetInfoById($Id);
    if (entity != null) {
        if (entity.FinancialMode == 1) {
            return "封闭结束日期：";
        }
        else {
            return "合同结束日期：";
        }
    }
    else {
        return "合同结束日期：";
    }
}
//计算天数差的函数，通用  
function DateDiff(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
    var aDate, oDate1, oDate2, iDays;
    aDate = sDate1.split("-");
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);    //转换为12-18-2006格式
    aDate = sDate2.split("-");
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);    //把相差的毫秒数转换为天数
    return iDays;
}